package data.dao;

import security.access.AccessCheckerFactory;
import security.crypto.CipherFactory;

public class DAOFactory {
	
	private static DAOFactory instance;
	
	private DAO recovered;
	private DAO repository;
	private DAO backup;
	
	private DAOFactory(String repository, 
			String recovered, String[] backup){
		
		AccessCheckerFactory.register(repository, recovered, backup);
		
		this.recovered = new SimpleDAO(AccessCheckerFactory.getRecoveredAccess());
		this.repository = new SimpleDAO(AccessCheckerFactory.getRepositoryAccess());
		this.backup = new SecuredDAO(AccessCheckerFactory.getBackupAccess(), CipherFactory.getCipher());
		
	}
	
	public static void register(String repository, 
			String recovered, String[] backup){
		if(instance != null)
			throw new RuntimeException("The paths have already been registred.");
		
		instance = new DAOFactory(repository,recovered,backup);
	}
	
	public static DAOFactory getInstance(){
		if(instance == null)
			throw new RuntimeException("No path has been registred yet.");
		return instance;
	}
	
	public static DAO getRecoveredDAO(){
		return getInstance().recovered;
	}
	
	public static DAO getBackupDAO(){
		return getInstance().backup;
	}
	
	public static DAO getRepositoryDAO(){
		return getInstance().repository;
	}
}
